#include "EpilStringExpressionCode.h"
#include "EpilOutputHelper.h"
#include "TCharSupport.h"


EpilStringExpressionCode::EpilStringExpressionCode( const EpilLexLocation & location )
: EpilExpressionCodeBase( location )
{
}


EpilStringExpressionCode::~EpilStringExpressionCode()
{
}


tstring EpilStringExpressionCode::ToEpilCode( int indent ) const
{
	tstringstream ret;
	ret << t("\"");
	
	for( size_t i = 0; i < m_string.length(); i++ )
	{
		switch( m_string[i] )
		{
		case t('\a'):
			ret << t("\\a");
			break;
		case t('\b'):
			ret << t("\\b");
			break;
		case t('\f'):
			ret << t("\\f");
			break;
		case t('\n'):
			ret << t("\\n");
			break;
		case t('\r'):
			ret << t("\\r");
			break;
		case t('\t'):
			ret << t("\\t");
			break;
		case t('\v'):
			ret << t("\\v");
			break;
		case t('\"'):
			ret << t("\\\"");
			break;
		default:
			if( m_string[i] < 32 )
			{
				int ch = m_string[i];
				ret << t("\\0");
				ret << oct << ch;
			}
			else
			{
				ret << m_string[i];
			}
			break;
		}
	}

	ret << t("\"");
	return ret.str();
}